package me.zhengjie.logging.service.dto

import cn.hutool.core.bean.BeanUtil
import cn.hutool.core.bean.copier.CopyOptions
import com.fasterxml.jackson.annotation.JsonTypeName
import me.zhengjie.common.utils.JacksonUtil
import org.apache.commons.lang3.builder.ToStringBuilder
import java.sql.Timestamp
/**
 * @author Kuki Wu
 * @date 2019-5-22
 */
@JsonTypeName("LogSmallDTO")
data class SysLogSmallDTO (
    // 描述
    var description: String? = null,

    // 请求ip
    var requestIp: String? = null,

    // 请求耗时
    var time: Long? = null,
    var address: String? = null,
    var browser: String? = null,

    // 创建日期
    var createTime: Timestamp? = null
){
    annotation class Update

    override fun toString(): String {
        val builder = ToStringBuilder(this)
        val fields = this.javaClass.declaredFields
        try {
            for (f in fields) {
                f.isAccessible = true
                builder.append(f.name, f[this]).append("\n")
            }
        } catch (e: Exception) {
            builder.append("toString builder encounter an error")
        }
        return builder.toString()
    }

    fun tojson(): String {
        return JacksonUtil.toJSONString(this)!!
    }

    fun copy(source:SysLogSmallDTO?) {
        BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true))
    }
}